
export class EventLister{
    
    private eventMgr = {}

    private static Instance : EventLister = null;

    static GetInstance(){
        if(EventLister.Instance == null){
            EventLister.Instance = new EventLister;
        }
        return EventLister.Instance;
    }

    private constructor(){}

    On(type : any,callback : any){
        if(this.eventMgr[type]){
            this.eventMgr[type].push(callback)
        }else{
            this.eventMgr[type] = [];
            this.eventMgr[type].push(callback);
        }
    }

    Emit(type : any,args : any){
        if(this.eventMgr.hasOwnProperty(type)){
            for(let i=0;i<this.eventMgr[type].length;++i){
                let event = this.eventMgr[type][i];
                event.call(this,args);
            }
        }else{
            console.log("UnKown Type:",type," ,Not Handle");
        }
    }

    CancelEvent(type : any){
        if(this.eventMgr.hasOwnProperty(type)){
            this.eventMgr[type] = []
        }
    }
    
    CancelAllEvent(){
        this.eventMgr = {}
    }
};